package czk.concrent.moreLock;

import java.util.concurrent.TimeUnit;

/**
 * @Author:ChenZhangKun
 * @Date: 2020/5/31 15:31
 */
// 活锁现象，线程永远无法执行完毕
public class AliveLock {
    private static volatile int count=10;
    public static void main(String[] args) {
        // 线程一
        new Thread(()->{
            while (count>0){
                try {
                    //TimeUnit.SECONDS.sleep((long) 0.2);
                    Thread.sleep(2*100);
                    System.out.println(count);
                    count--;
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"t1").start();
        // 线程二
        new Thread(()->{
            while (count<20){
                try {
                    Thread.sleep(2*100);
                    //TimeUnit.SECONDS.sleep((long) 0.2);
                    System.out.println(count);
                    count++;
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"t2").start();
    }
}
